﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using stud.configurations;
using stud.DTOs;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (headerMenu.Items.Count == 0)
        {
            var userRoles = Roles.GetRolesForUser(Membership.GetUser().UserName).ToList();
            List<MenuItemInfo> menuItems = SiteMenuConfig.GetMenuItem();
            foreach (var menuItemInfo in menuItems)
            {
                if (menuItemInfo.Roles.Contains("*"))
                {
                    headerMenu.Items.Add(new MenuItem
                                             {
                                                 Text = menuItemInfo.MenuText + " | ",
                                                 NavigateUrl = menuItemInfo.NavigateUrl
                                             });
                    continue;
                }
                foreach (var userRole in userRoles)
                {
                    if (menuItemInfo.Roles.Contains(userRole))
                        headerMenu.Items.Add(new MenuItem
                                                 {
                                                     Text = menuItemInfo.MenuText + " | ",
                                                     NavigateUrl = menuItemInfo.NavigateUrl
                                                 });
                }
            }
        }
        ////MenuItem menuHeaderItems = ;

        //headerMenu.Items.Add(new MenuItem { Text = "Home | ", NavigateUrl = "~/Default.aspx" });
        //headerMenu.Items.Add(new MenuItem { Text = " Bank", NavigateUrl = "~/Bank.aspx" });

    }
}
